package com.sbtr.controller.feature;

import com.sbtr.business.feature.dto.FeFilterRuleDto;
import com.sbtr.business.feature.entity.FeFilterRule;
import com.sbtr.business.feature.service.FeFilterRuleService;
import com.sbtr.common.PageDto;
import com.sbtr.common.Response;
import com.sbtr.controller.common.CommonController;
import com.sbtr.exception.BDException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 条件过滤字段列表 前端控制器
 *
 * @author dgl
 * @since 2023-03-17
 */
@RestController
@RequestMapping("/feFilterRule")
@Api(tags = "条件过滤字段列表")
public class FeFilterRuleController extends CommonController<FeFilterRule, FeFilterRuleService> {

    @Autowired
    private FeFilterRuleService feFilterRuleService;

    @GetMapping("/pageList")
    @ApiOperation(httpMethod = "GET", value = "条件过滤字段列表列表")
    public Response<PageDto<FeFilterRule>> pageList(FeFilterRuleDto feFilterRuleDto){
        return Response.success(feFilterRuleService.pageList(feFilterRuleDto));
    }

    @PostMapping("/save")
    @ApiOperation(httpMethod = "POST", value = "条件过滤字段列表保存")
    public Response<FeFilterRule> save(@RequestBody FeFilterRule feFilterRule){
        feFilterRule.setId(null);
        if(feFilterRule.insert()){
            return Response.success(feFilterRule);
        }else throw new BDException("保存失败");
    }

}

